<%@ page import="core.*, model.*, java.util.*" %>

<%@ include file='header.tpl.jsp'%>

<script type="text/javascript" src="js/check_answer.js"></script>

<form action="CheckAnswer" method="post">

<%
Paper p = (Paper) request.getAttribute("paper");
if(p == null){
	p = new Paper();
}
UserGroup usergroup = user.getGroup();
ChoiceQuestion[] qlist = (ChoiceQuestion[]) request.getAttribute("question_list[]");
Integer[] qpoint = p.getPid() > 0 ? (Integer[]) request.getAttribute("qpoint[]") :null;
for(int n = 0; n < qlist.length; n++){
	ChoiceQuestion q = qlist[n];
%>
	<div class="box">
		<div style="float:right">
		<%if(usergroup.hasPermission(UserGroup.EDIT_QUESTION)){%>
			<a href="EditQuestion?qid=<%=q.getQid()%>">[Edit]</a>
		<%}%>
		<%if(usergroup.hasPermission(UserGroup.DELETE_QUESTION)){%>
			<a href="DeleteQuestion?qid=<%=q.getQid()%>">[Delete]</a>
		<%}%>
		</div>
		<h2><%=q.getContent()%><%if(p.getPid() > 0){%> (<span class="point"><%=qpoint[n]%></span> point<%if(qpoint[n] > 1){%>s<%}%>)<%}%></h2>
		<ul class="options">
		<%String[] options = q.getOptions();%>
		<%if(q.getAnswer().length() == 1){%>
			<%for(int i : q.getRandomOptionKeys()){%>
				<li>
					<label>
						<input type="radio" id="id_<%=q.getQid()%>" name="id_<%=q.getQid()%>" value="<%=i%>" />
					<%=options[i]%>
					</label>
				</li>
			<%}%>
		<%}else{%>
			<%for(int i : q.getRandomOptionKeys()){%>
				<li>
					<input type="checkbox" id="id_<%=q.getQid()%>[<%=i%>]" name="id_<%=q.getQid()%>[<%=i%>]" />
					<label for="id_<%=q.getQid()%>[<%=i%>]"><%=options[i]%></label>
				</li>
			<%}%>
		<%}%>
		</ul>
	</div>
<%}%>

<%if(p != null && p.getPid() > 0){%>
	<%if(user.isLoggedIn()){%>
	<input type="hidden" id="pid" name="pid" value="<%=p.getPid()%>" />
	<%}%>
	<%if(p.getTimeout() > 0){%>
	<div id="counter"></div>
	<script type="text/javascript" src="js/jquery.countdown.js"></script>
	<script type="text/javascript">
	timer_interval = $('#counter').countdown({
		startTime: secondTimeFormat(<%=p.getTimeout()%>),
		timerEnd: function(){postAnswer();}
	});
	$('#counter')
	.css('position', 'fixed')
	.css('top', $(window).height() - $('#counter').outerHeight() - 10)
	.css('left', $(window).width() - $('#counter').outerWidth() - 10);
	</script>
	<%}%>
<%}%>

<div class="post_buttons">
<%if(user.getGroup().hasPermission(UserGroup.ANSWER_QUESTION)){%>
	<button type="submit" onclick="postAnswer();return false;">Submit your answers</button>
<%}%>
</div>

</form>

<%@ include file='footer.tpl.jsp'%>